/**
 * Created by Pyj on 2019/08/20.
 */
/***********************面板-start****************************/
var rowData=[];

//应用主列表参数面板
var reportGridOpt={
    id:"reportGrid",//渲染对象ID 控件的唯一标识
    autoWidth:true,
    autoHeight:true,
    className:"test",//表格样式类名
    isMulitCheck:true,//是否支持多选
    loadMsg:"正在加载数据请稍等",//表格加载显示信息
    rowData:rowData,
    root:"data",//服务端返回的数据对象名
    url:basePath+"/reporttab/list",
    columns:[
        {
            hidden : false,
            label : "报表名称",
            name : "name",
            width : "40"
        },
        {
            hidden : false,
            label : "有效期",
            name : "startTime",
            width : "60",
            formatter: function (columnValue,rowData) {
                return formatDateTime(columnValue)+"-"+formatDateTime(rowData.endTime)
            }
        },
        {
            hidden : false,
            label : "状态",
            name : "status",
            width : "20",
            formatter : function(columnValue) {
                if(columnValue==1){
                    return "启用";
                } else if(columnValue==0) {
                    return "禁用";
                }
            }
        },
        {
            hidden : false,// 是否隐藏该列
            label : "操作",// 显示列名称
            name : "id",// 列字段属性名`
            width : "200",// 列宽度
            isOrder : true,// 是否排序
            isFmtHtml:true,//格式化是否返回html
            formatter : function(columnValue,rowData){
                var btns=[];
                var testBtn = $("<a class='gridedit_btn' style='color:red;margin-left: 10px;' \">测试按钮</a>");
                testBtn.bind("click", function () {
                    submit();
                });
                btns.push(testBtn);

                var testBtn2 = $("<a class='gridedit_btn' style='color:red;margin-left: 10px;' \">获取人员</a>");
                testBtn2.bind("click", function () {
                    getUserAudit();
                });
                btns.push(testBtn2);

                var testBtn3 = $("<a class='gridedit_btn' style='color:red;margin-left: 10px;' \">生成报表</a>");
                testBtn3.bind("click", function () {
                    createStatisForm();
                });
                btns.push(testBtn3);

                var testBtn4 = $("<a class='gridedit_btn' style='color:red;margin-left: 10px;' \">查询测试</a>");
                testBtn4.bind("click", function () {
                    searchTest();
                });
                btns.push(testBtn4);
                return btns;
            }
        }
    ],
    event:{
        readyLoad:function(opt,gridObj){//grid数据加载前执行
            $(".panel").css("display","none");
        },
        restGridHeight:function(gridHeight,gridObj){
            return gridHeight-$("#searchForm").height();
        },
        onRowMouse:function (rowData,gridObj) {
            return [];
        },
    }
};

//应用添加面板参数
var addAppPanelOpt = {
    bombType:BOMB_TYPE2,
    valForm:{
        valParam:[//验证参数
            {
                inputname:"name_App_AddPanel",
                isnull:true,
                isnullmsg:"应用名称不能为空！",
                event:"submit"
            },
            {
                inputname:"cycle_App_AddPanel",
                isnull:true,
                isnullmsg:"填报周期不能为空！",
                event:"submit"
            },
            {
                inputname:"frequency_App_AddPanel",
                isnull:true,
                isnullmsg:"填报频次不能为空！",
                event:"submit"
            },
            {
                inputname:"beginDt",
                isnull:true,
                isnullmsg:"开始时间不能为空！",
                event:"submit"
            },
            {
                inputname:"endDt",
                isnull:true,
                isnullmsg:"开始时间不能为空！",
                event:"submit"
            }
        ]
    },//验证
    action:basePath+"/app/addApp",//表单提交地址
    event:{
        onClosed:function(obj){

        },
        okBtnClick:function(eventObj,panel){

        },
        submitSuccessed:function(data,panelObj){
            setTimeout(function(){
                panelObj.close();
                $("#reportGrid").wdfGrid("reload",reportGridOpt);
            },500);
        }
    }
};

//应用编辑面板参数
var editAppPanelOpt = {
    width:width,//高
    height:height,//宽
    bombType:BOMB_TYPE2,
    valForm:{
        valParam:[//验证参数
            {
                inputname:"name_App_EditPanel",
                isnull:true,
                isnullmsg:"应用名称不能为空！",
                event:"submit"
            },
            {
                inputname:"appType_App_EditPanel",
                isnull:true,
                isnullmsg:"应用类型不能为空！",
                event:"submit"
            }
        ]
    },//验证
    action:basePath+"/app/editApp",//表单提交地址
    event:{
        onClosed:function(obj){

        },
        okBtnClick:function(eventObj,panel){

        },
        submitSuccessed:function(data,panelObj){
            setTimeout(function(){
                reportGridOpt.keepPage=true;
                panelObj.close();
                $("#reportGrid").wdfGrid("reload",reportGridOpt);
            },500);
        }
    }
};

/***********************面板-end****************************/

/***********************通用下拉列表-start****************************/


/***********************通用下拉列表-end****************************/

/***********************业务操作-start****************************/
//应用添加
function addReport(){
    $(".evalutePannel").css("display","block");
    $(".evalutePannelTop_title").html("添加报表");
    $("#reporttype_id_pannel").val("");
    $("#name_report_AddPanel").val("");
    $("#frequency_report_AddPanel").val("");
    $("#beginDt").val("");
    $("#endDt").val("");
}

//应用编辑
function editReport(rowData){
    $(".evalutePannel").css("display","block");
    //加载编辑数据
    if(rowData!=undefined){
        $(".evalutePannelTop_title").html("编辑报表");
        $("#reporttype_id_pannel").val(rowData.id);
        $("#reporttype_status_pannel").val(rowData.status);
        $("#name_report_AddPanel").val(rowData.name);
        $("#cycle_report_AddPanel").val(getOptionConstant(reportTypeConstant,rowData.cycle));
        $("#frequency_report_AddPanel").val(rowData.frequency);
        $("#beginDt").val(formatDate(rowData.startTime));
        $("#endDt").val(formatDate(rowData.endTime));
    }
}

function closeScorePannel(){
    $(".evalutePannel").css("display","none");
}

function getUserAudit(){
    var requestUrl="/workFlow/getNodeFlowUsers";
    var params={};

    //区长审核人拉取
    // params.flowNodeId = 3;
    // params.isCurrent=1;
    // params.orgIds=7; //久长服务区机构id=9

    //商户处理人拉取
    params.flowNodeId = 4;
    params.isCurrent=1;
    params.orgIds=10; //商户机构id

    //区长验收人拉取
    //  params.flowNodeId = 11;
    //  params.isCurrent=1;

    $.ajax({
        url:basePath+requestUrl,
        async: true,
        dataType: "json",
        type: "POST",
        contentType: "application/x-www-form-urlencoded",
        data:params,
        beforeSend: null,
        success: function (data) {
            $.wdfProgress.showMsg(data.msg, $("body"), true);
            if (data.status==SUCCESS){

            }else{
                alert(data.msg);
            }
        }
    });
}

function submit(){

    var params;
    //创建工单
    // var requestUrl="/xunjian/createXunjianForm";
    // params=createWorkFormParam();

    //区长审核工单
    // var requestUrl="/xunjian/quzhangAuditForm";
    // params=quzhangAuditParam();

    //商家处理工单
    // var requestUrl="/xunjian/shopDealwithForm";
    // params=shopDealwithParam();

    //区长验收工单
    // var requestUrl="/xunjian/quzhangCheckForm";
    // params=quzhangCheckParam();

    //拉取工作流列表
    var requestUrl="/xunjian/getWorkFlowStoreFormList";
    params={
        "curPage":1,
        "pageSize":100,
        "flowNodeId":'3,11',
        "tStatus":0,
        "processerIds":9
    };

    $.ajax({
        url:basePath+requestUrl,
        async: true,
        dataType: "json",
        type: "POST",
        contentType: "application/x-www-form-urlencoded",
        data:params,
        beforeSend: null,
        success: function (data) {
            $.wdfProgress.showMsg(data.msg, $("body"), true);
            if (data.status==SUCCESS){
                setTimeout(function() {
                    alert("处理成功");
                }, 500);
            }else{
                alert(data.msg);
            }
        }
    });


}

function createWorkFormParam() {
    var workForm={};
    workForm.serviceAreaId = 4;
    workForm.pointMainId = 1;
    workForm.commitUserId = 1;
    workForm.reportTypeId=1;
    workForm.haveProblem = 1;
    workForm.status = 1;
    var params={
        "workForm":JSON.stringify(workForm)
    };

    var values=[];
    var value={};
    value["serviceAreaId"]=4;
    value["pointMainId"]=1;
    value["reportTypeId"]=1;
    value["problemId"]=1;
    value["problemUrl"]="1,2";
    value["storeDeptIDS"]="9,10";
    values.push(value);

    params.storeForms = JSON.stringify(values);

    params.processerID=1;

    return params;
}

function quzhangAuditParam() {

    var params={

    };
    params.tID =36;
    params.bID=2;
    params.cutoffTime = "2020-10-27 17:40:00";
    params.storeDeptId=11;
    params.isModifyShop = true;
    params.processerID=1;
    params.auditStatus=1;

    return params;
}

function shopDealwithParam() {

    var params={

    };
    params.tID =39;
    params.bID=2;
    params.dealTime = "2020-10-27 17:50:00";
    params.dealwithUrl="1,2,3";
    params.remark = "已处理完成";
    params.processerID=1;

    return params;
}

function quzhangCheckParam() {

    var params={

    };
    params.tID =40;
    params.bID=2;
    params.auditStatus = 1;

    return params;
}

function createStatisForm(){
    var requestUrl="/static/createStaticWorkForm";
    var params={};

    params.id = 1;

    $.ajax({
        url:basePath+requestUrl,
        async: true,
        dataType: "json",
        type: "POST",
        contentType: "application/x-www-form-urlencoded",
        data:params,
        beforeSend: null,
        success: function (data) {
            $.wdfProgress.showMsg(data.msg, $("body"), true);
            if (data.status==SUCCESS){

            }else{
                alert(data.msg);
            }
        }
    });
}

function searchTest(){
    var requestUrl="/static/getXunjianHistoryList";
    var params={

    };

    params.id = 1;

    $.ajax({
        url:basePath+requestUrl,
        async: true,
        dataType: "json",
        type: "POST",
        contentType: "application/x-www-form-urlencoded",
        data:params,
        beforeSend: null,
        success: function (data) {
            $.wdfProgress.showMsg(data.msg, $("body"), true);
            if (data.status==SUCCESS){

            }else{
                alert(data.msg);
            }
        }
    });
}

//应用条件查询
function search() {
    reportGridOpt.param=$("#searchForm").serialize().replace(/\+/g,"");
    $("#reportGrid").wdfGrid("reload",reportGridOpt);
}

//条件查询重置
function resetSearch() {
    $('#searchForm')[0].reset();
    search();
}

//验证消息显示
function showMsg(msg,input,obj){
    var msgBar=$("<div class='msgBar'>"+msg+"</div>");
    $(".msgBar").remove();
    obj.append(msgBar);
    msgBar.animate({"opacity":1},500);
    $(input).data("showMsg",msgBar);
    $(input).addClass("error");
};

/*判断对象值是否为空*/
function ifNULL(obj) {
    var flag = false;
    if (obj == null || obj == undefined || obj == '') {
        flag = true;
    }
    return flag;
}

/***********************业务操作-end****************************/

/***********************页面初始化-start****************************/
$(document).ready(function() {
    reportGridOpt.param=$("#searchForm").serialize();
    reportGridOpt.height = $(document).height() - $('#searchPanel').height()-20;
    $("#reportGrid").wdfGrid("init",reportGridOpt);

    addAppPanel=$("#addAppPanel").wdfPanel("FormPanel",addAppPanelOpt);
    editAppPanel=$("#editAppPanel").wdfPanel("FormPanel",editAppPanelOpt);

});
/***********************页面初始化-end****************************/